{% extends 'layout/manage.html' %}
{% load static %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">

    <style>
        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body .item {
            border-radius: 6px;
            width: 226px;
        {#height: 113px;#} border: 1px solid #dddddd;
            margin: 20px 10px;
        }

        .panel-body .item:hover {
            border: 2px solid #f0ad4e;
        }

        .panel-body .item .title {
            text-align: center;
            line-height: 104px;
        }

        .panel-body .item .title a {
            display: inline-block;
            width: 100%;
            height: 104px;
            color: #ffffff;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 24px;
            text-decoration: none;
        }

        .panel-body .item .info {
            padding: 10px 10px;
            display: flex;
            justify-content: space-between;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            color: #8c8c8c;
        }

        .panel-body .item .info a {
            text-decoration: none;
        }

        .panel-body .item .info .fa-star {
            font-size: 18px;
        }

        #id_color label {
            margin-left: 0;
            padding-left: 0;
        }

        #id_color input[type='radio'] {
            opacity: 0;
            display: none;
        }

        #id_color input[type='radio'] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        #id_color input[type='radio']:checked + .cycle {
            border: 3px solid black;
        }
    </style>
{% endblock %}
{% block content %}
    <div class="container-fluid">
        <a class="btn btn-success" data-toggle="modal" data-target="#addModal">
            <i class="fa fa-plus-circle" aria-hidden="true"></i>
            新建项目
        </a>

        <div class="panel panel-default" style="margin-top: 15px">
            <div class="panel-heading">
                <i class="fa fa-star" aria-hidden="true"></i>
                星标项目
            </div>
            <div class="panel-body">
                {% for item in project_dict.star %}
                    <div class="item">
                        {#                        <a href="#" class="title" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>#}
                        <div class="title">
                            <a href="{% url 'dashboard' project_id=item.value.id %}"
                               style="background-color:{{ item.value.get_color_display }};">{{ item.value.name }}</a>
                            {#                            <a href="manage/{{ item.value.id }}/dashboard/"#}
{#                            style="background-color:{{ item.value.get_color_display }};">{{ item.value.name }}</a>#}
                        </div>
                        <div class="info">
                            <div>
                                {#                                <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">#}
                                <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">

                                    {#                                <a href="{% url 'web:project_star' project_type='my' project_id=item.id %}">#}
                                    {#                                <a href="/project/star/{{ item.type }}/{{ item.value.id }}">#}
                                    <i class="fa fa-star" aria-hidden="true" style="color: #f8dc48"></i>
                                </a>
                                <span>{{ item.value.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.value.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}

            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-list" aria-hidden="true"></i>
                我创建的项目
            </div>
            <div class="panel-body">
                {% for item in project_dict.my %}
                    <div class="item">
                        {#                        <a href="#" class="title" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>#}
                        <div class="title">
                            {#                            <a href="manage/{{ item.id }}/dashboard/" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>#}
                            <a href="{% url 'dashboard' project_id=item.id %}" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>
                        </div>
                        <div class="info">
                            <div>
                                {#                                <a href="/project/star/project_type=my/project_id={{ item.id }}">#}
                                {#                                <a href="project/star/my/{{ item.id }}">#}
                                <a href="{% url 'project_star' project_type='my' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                                </a>
                                <span>{{ item.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-handshake-o" aria-hidden="true"></i>
                我参与的项目
            </div>
            <div class="panel-body">
                {% for item in project_dict.join %}
                    <div class="item">
                        {#                        <a href="#" class="title" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>#}
                        <div class="title">
                            <a href="manage/{{ item.id }}/dashboard/" style="background-color:{{ item.get_color_display }};">{{ item.name }}</a>
                        </div>
                        <div class="info">
                            <div>
                                <a href="/project/star/project_type=join/project_id={{ item.id }}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                                </a>
                                <span>{{ item.creator.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}

            </div>
        </div>

    </div>

    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    <form id="addForm">
                        {% csrf_token %}
                        {% for item in form %}
                            <div class="form-group">
                                <label for="{{ item.id_for_label }}">{{ item.label }}</label>
                                {{ item }}
                                <span class="error-msg">{{ item.errors.0 }}</span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">提 交</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        $(function () {
            binkClickbtnSubmit()
        });

        function binkClickbtnSubmit() {
            $("#btnSubmit").click(function () {
                $.ajax({
                    url: "/project/list/",
                    type: "post",
                    data: $("#addForm").serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        console.log(res)
                        if (res.status) {
                            // 成功后让页面主动刷新
                            location.href = location.href;
                            {#location.reload()#}
                        } else {
                            $.each(res.error, function (key, value) {
                                $('#id_' + key).next().text(value[0])
                            });
                            {#console.log(res.error())#}
                        }
                    }
                });
            });
        }
    </script>

{% endblock %}